package test.dataprovider;

import java.sql.Connection;
import java.sql.SQLException;

import javax.annotation.PreDestroy;
import javax.sql.DataSource;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import test.BaseTester;
import test.util.Constants;

public class SpringCongrationTester extends BaseTester {
    @Autowired
    private DataSource dataSource;

    @PreDestroy
    public void after() {
        this.dataSource = null;
    }

    @Test
    public void test() {
        Connection conn = null;
        try {
            conn = this.dataSource.getConnection();
            Assert.assertTrue(conn.isValid(Constants.ONE));
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
        } finally {
            if (null != conn) {
                try {
                    conn.close();
                    Assert.assertTrue(conn.isClosed());
                    conn = null;
                } catch (SQLException e) {
                    e.printStackTrace();
                    Assert.fail(e.getMessage());
                }
            } else
                Assert.fail();
        }
    }
}
